# encoding: UTF-8
$LOAD_PATH.unshift File.dirname(__FILE__)
require 'User'

class Teacher < User
  attr_accessor :disciplines, :school, :mastering_class

  def initialize(login, password, name, surname)
    super(login, password, name, surname)
    @disciplines = []
  end;
  
  def write_mark(student, mark)
    student.marks << mark
  end
  
  def add_discipline (discipline)
    disciplines << discipline
  end
  
  def class_average_for(discipline)
    students_number = 0
    averages_sum = 0
    mastering_class.students.each do |student|
      student_average = student.average_for discipline
      if not student_average.nil?
        averages_sum += student_average
        students_number += 1
      end
    end
    if students_number == 0
      nil
    else
      averages_sum / students_number
    end
  end
end